import RPi.GPIO as GPIO
import serial
import string
import binascii
import time

ser = serial.Serial("/dev/ttySC1", 9600, timeout=1)

# Send modbus device inquiry frame (hex code)
str1 = bytes.fromhex("01 05 00 01 FF 00 DD FA ")
res = ser.write(str1)
print(res)
print(str1)
# Modbus device returns response frame rate (hex code)
ser.flushInput()
data = ""
print("You can always receive data, press Ctrl + C to exit")
while 1:
    while ser.inWaiting() > 0:
        data = ser.readline()
    if data != "":
        print(str(binascii.b2a_hex(data))[2:-1])
        data = ""
